<?
#include("DataBase.class.php");
#include("../../classes/business/socios/Socio.class.php");
class ORM{


    public static function Load(&$object, $sql)
    {
		$results = DataBase::ExecuteQuery($sql, "ARRAY");
		
		
		$keys = array_keys($results[0]);
		$string_keys = array();
		
		foreach($keys as $value){
			if(!is_int($value))
				array_push($string_keys, $value);
		}
		$row = $results[0];

		foreach($string_keys as $value)
			$object->$value = $row[$value];			

    }
	
			public static function InsertStatement($object, $table_name){				
			
			$sql = "INSERT INTO $table_name SET ";
			
			foreach($object as $key => $value)
				if($key != id)					$sql .= "$key = '$value', ";
			
			$sql = substr($sql,0,strlen($sql)-2); // removing the last comma ','
			
			return	$sql;
		}#update

	
		public static function UpdateStatement($object, $table_name){	
			$sql = "UPDATE $table_name SET ";
			
			foreach($object as $key => $value)
				if($key != id)					$sql .= "$key = '$value', ";
			
			$sql = substr($sql,0,strlen($sql)-2); // removing the last comma ','
			
			return	$sql .= " WHERE id = ".$object->id;
		}#update
		
		public static function DataBinding(&$object, $request){

			foreach ($object as $key => $value)
				$object->$key = $request[$key];			
								
		}#end DataBinding
}

#$socio = new Socio();
#ORM::Load($socio, "SELECT * FROM socios WHERE id = 3");
#echo ORM::UpdateStatement($socio, "socios");
#print_r($socio);
?>